// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
const baseUrl = "http://172.16.33.78:8080";
Component({
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    banners:[
        {images:'http://172.16.33.78/ku/banner_1.png',title:''},
        {images:'http://172.16.33.78/ku/banner_2.png',title:''},
        {images:'http://172.16.33.78/ku/banner_3.png',title:''}
    ],
    users:[
        {images:'http://172.16.33.78/ku/user_1.png',title:''},
        {images:'http://172.16.33.78/ku/user_2.png',title:''},
        {images:'http://172.16.33.78/ku/user_3.png',title:''},
        {images:'http://172.16.33.78/ku/user_4.png',title:''},
        {images:'http://172.16.33.78/ku/user_5.png',title:''},
        // {images:'http://172.16.33.78/ku/user_6.png',title:''}
    ],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    search:{
        "pageNum": 1,
        "pageSize": 10,
        "search": {}
      }
  },
  lifetimes:{
    ready: function () {
        this.loadData();
    },
  },
  methods: {
      loadData() {
        const that = this
        wx.request({
            url: baseUrl+'/api/love/user/search',
            method: 'POST',
            data: that.data.search,
            header: {
                'content-type': 'application/json' // 默认值
            },
            success (res) {
              const {list} = res.data
              that.setData({
                  users: list
              })
            }
          })
      },
    // 事件处理函数
    bindViewTap() {
      wx.navigateTo({
        url: '../logs/logs'
      })
    },
    onChooseAvatar(e) {
      const { avatarUrl } = e.detail
      const { nickName } = this.data.userInfo
      this.setData({
        "userInfo.avatarUrl": avatarUrl,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
      })
    },
    onInputChange(e) {
      const nickName = e.detail.value
      const { avatarUrl } = this.data.userInfo
      this.setData({
        "userInfo.nickName": nickName,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
      })
    },
    getUserProfile(e) {
      // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
      wx.getUserProfile({
        desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: (res) => {
          console.log(res)
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    },
  },
})
